<?php
class class_BD {
	var $bd;
	var $servidor;
	var $usuario;
	var $clave;
	var $manejador_BD;
	var $conexion_ID=0;
	var $consulta_ID=0;
	
	
	/*===============================================================================//
		Encripta la Clave para Base de Datos
	//===============================================================================*/
	function cocdpplbd( $pass_actual ) { 
		if ( $pass_actual == "123456" ) {
			$_SESSION['encripass'] = "SI";
			$new_pas_good = $pass_actual;
		} else {
			$_SESSION['encripass'] = "NO";
			$anc_var 	= strlen($pass_actual);
			$indice 	= $anc_var - 1;
			while ( $indice >= 0 ) {
				$val 	= substr($pass_actual,$indice,1);
				if ( is_numeric($val) ) {
				} else {
					$ordinalwert = (ord($val) - 64);
					$val = $ordinalwert * pow(26,0);
					$val = $val + 23;
				}
				
				$base = ($val * 1) + $indice;
				if ( $resto == 0 ) {
				} else {
					$base = ($base * 1) + ($resto * 1);
				}
				$resto = 0;
				if ( strlen($base) > 1 ) {
					$resto 	= substr($base,0,1);
					$base_2 = substr($base,1,1);
					$new_pas_good = $new_pas_good.$base_2;
				} else {
					$new_pas_good = $new_pas_good.$base;
				}
				$indice--;
			}
		}
		return $new_pas_good;
	}
	
	
	function conexion_BD( $manejador_BD = "", $usuario = "", $clave = "", $bd = "", $servidor = "" ) {
		if ( $manejador_BD == "" || $usuario == "" || $clave == "" || $bd == "" || $servidor == "" ) {
			return 999;
		}
		else{}
		
		$this->bd			= $bd;
		$this->servidor		= $servidor;
		$this->manejador_BD	= $manejador_BD;
		$this->usuario		= $usuario;
		$this->clave		= $this->cocdpplbd($clave);
		
		switch ( $this->manejador_BD ) {
			case 'mysql':	$this->conexion_ID = @mysql_connect($this->servidor, $this->usuario, $this->clave);
							if ( $this->conexion_ID ) {
								if ( !@mysql_select_db($this->bd) ) {
									return 'FALSE';
								}
							}
							break;
			case 'sybase':	$this->conexion_ID = @sybase_connect($this->servidor, $this->usuario, $this->clave, iso_1);
							if ( $this->conexion_ID ) {
								if ( !@sybase_select_db($this->bd) ) {
									return 'FALSE';
								}
							} else {
								return 'FALSE';
							}
							break;
		}
		return $this->conexion_ID;
	}
	
	function desconectar_BD() {
		switch ( $this->manejador_BD ) {
			case 'mysql':	$success = @mysql_close($this->conexion_ID);
							break;
			case 'sybase':	$success = @sybase_close($this->conexion_ID);
							break;
		}
		return $success;
	}
	
	function consulta_BD( $sql = "" ) {
		if ( $sql == "" ) {
			return 0;
		} else {
			$consulta = $sql;
		}
		switch ( $this->manejador_BD ) {
			case 'mysql':	$this->consulta_ID = @mysql_query($consulta, $this->conexion_ID);
							break;
			case 'sybase':	$this->consulta_ID = @sybase_query($consulta, $this->conexion_ID);
							break;
		}
		return $this->consulta_ID;
	}
	
	function libera_espacio_BD() {
		switch ( $this->manejador_BD ) {
			case 'mysql':	$this->conexion_ID = @mysql_free_result($this->consulta_ID);
							break;
			case 'sybase': 	$this->conexion_ID = @sybase_free_result($this->consulta_ID);
							break;
		}
		return $this->conexion_ID;
	}
	
	function num_rows_BD() {
		switch ( $this->manejador_BD ) {
			case 'mysql':	$num_rows = @mysql_num_rows($this->consulta_ID);
							break;
			case 'sybase':	$num_rows = @sybase_num_rows($this->consulta_ID);
							break;
		}
		return $num_rows;
	}
	
	function get_last_message_BD() {
		switch ( $this->manejador_BD ) {
			case 'mysql':	//	Hay que buscar el equivalente de MySql....
							//$messag e= @mysql_get_last_message($this->consulta_ID);
							break;
			case 'sybase':	$message = @sybase_get_last_message($this->consulta_ID);
							break;
		}
		return $message;
	}
	
	function fetch_array_BD( $rs_conn = "" ) {
		$temparray = array();
		if ( $rs_conn == "" ) {
			$rs_conn = $this->consulta_ID;
		}
		switch ( $this->manejador_BD ) {
			case 'mysql':	$temparray = @mysql_fetch_array($rs_conn);
							break;
			case 'sybase':	$temparray = @sybase_fetch_array($rs_conn);
							break;
		}
		return $temparray;
	}
}
?>